package com.example.demo.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * DMN 测试控制器
 * 提供简单的 DMN 功能测试
 */
@RestController
@RequestMapping("/api/dmn-test")
public class DmnTestController {

    /**
     * 测试 DMN 决策引擎是否正常工作
     */
    @GetMapping("/health")
    public Map<String, Object> healthCheck() {
        Map<String, Object> result = new HashMap<>();
        result.put("status", "UP");
        result.put("message", "DMN 决策引擎运行正常");
        result.put("timestamp", System.currentTimeMillis());
        return result;
    }

    /**
     * 获取 DMN 示例数据
     */
    @GetMapping("/examples")
    public Map<String, Object> getExamples() {
        Map<String, Object> examples = new HashMap<>();
        
        // 请假审批示例
        Map<String, Object> leaveExample = new HashMap<>();
        leaveExample.put("employee", "张三");
        leaveExample.put("employeeLevel", "普通员工");
        leaveExample.put("days", 3);
        leaveExample.put("leaveType", "病假");
        examples.put("leaveApproval", leaveExample);
        
        // 风险评估示例
        Map<String, Object> riskExample = new HashMap<>();
        riskExample.put("projectType", "软件开发");
        riskExample.put("budget", 100000);
        riskExample.put("teamSize", 5);
        riskExample.put("experience", "中级");
        examples.put("riskAssessment", riskExample);
        
        // 折扣计算示例
        Map<String, Object> discountExample = new HashMap<>();
        discountExample.put("customerType", "VIP");
        discountExample.put("orderAmount", 2000.0);
        discountExample.put("loyaltyPoints", 500);
        discountExample.put("season", "春季");
        examples.put("discountCalculation", discountExample);
        
        return examples;
    }

    /**
     * 获取 DMN 决策表信息
     */
    @GetMapping("/decisions-info")
    public Map<String, Object> getDecisionsInfo() {
        Map<String, Object> info = new HashMap<>();
        
        Map<String, Object> leaveDecision = new HashMap<>();
        leaveDecision.put("name", "请假审批决策");
        leaveDecision.put("description", "根据员工级别、请假天数和类型决定审批流程");
        leaveDecision.put("inputs", new String[]{"employeeLevel", "days", "leaveType"});
        leaveDecision.put("outputs", new String[]{"approvalResult", "approverLevel", "needHRApproval"});
        info.put("leaveApprovalDecision", leaveDecision);
        
        Map<String, Object> riskDecision = new HashMap<>();
        riskDecision.put("name", "风险评估决策");
        riskDecision.put("description", "根据项目类型、预算、团队规模和经验评估风险等级");
        riskDecision.put("inputs", new String[]{"projectType", "budget", "teamSize", "experience"});
        riskDecision.put("outputs", new String[]{"riskLevel", "recommendedAction", "requiredApproval"});
        info.put("riskAssessmentDecision", riskDecision);
        
        Map<String, Object> discountDecision = new HashMap<>();
        discountDecision.put("name", "折扣计算决策");
        discountDecision.put("description", "根据客户类型、订单金额、积分和季节计算折扣");
        discountDecision.put("inputs", new String[]{"customerType", "orderAmount", "loyaltyPoints", "season"});
        discountDecision.put("outputs", new String[]{"discountRate", "finalAmount", "bonusPoints"});
        info.put("discountCalculationDecision", discountDecision);
        
        return info;
    }
}

